﻿package mortal.game.resource
{
    import com.gengine.resource.*;
    import com.gengine.utils.*;
    import flash.geom.*;
    import flash.utils.*;
    import mortal.game.resource.info.*;

    public class DramaEffectConfig extends Object
    {
        private var _map:Dictionary;
        private static var _instance:DramaEffectConfig;

        public function DramaEffectConfig()
        {
            this._map = new Dictionary();
            if (_instance != null)
            {
                throw new Error(" ResConfig 单例 ");
            }
            this.init();
            return;
        }// end function

        private function write(param1:Object) : void
        {
            var _loc_2:DramaEffectInfo = null;
            var _loc_3:Object = null;
            for each (_loc_3 in param1.drama)
            {
                
                _loc_2 = new DramaEffectInfo();
                _loc_2.code = _loc_3.code;
                _loc_2.src = _loc_3.src;
                _loc_2.points = this.toPointArray(_loc_3.points);
                _loc_2.moveType = this.toNumberArray(_loc_3.moveType);
                _loc_2.moveTime = this.toNumberArray(_loc_3.moveTime);
                _loc_2.repeatCount = _loc_3.repeatCount;
                _loc_2.repeatInterval = _loc_3.repeatInterval;
                _loc_2.sound = _loc_3.sound;
                _loc_2.scale = this.toNumberArray(_loc_3.scale);
                _loc_2.delay = _loc_3.delay;
                _loc_2.effectType = _loc_3.effectType;
                _loc_2.isXML = _loc_2.src.indexOf(".xml") > -1;
                this._map[_loc_3.code] = _loc_2;
            }
            return;
        }// end function

        private function toPointArray(param1:String) : Array
        {
            var _loc_3:Array = null;
            var _loc_4:int = 0;
            var _loc_5:String = null;
            var _loc_6:Array = null;
            param1 = StringHelper.trim(param1);
            var _loc_2:Array = [];
            if (param1.length > 2)
            {
                _loc_3 = param1.split(";");
                _loc_4 = 0;
                while (_loc_4 < _loc_3.length)
                {
                    
                    _loc_5 = _loc_3[_loc_4];
                    _loc_6 = this.toNumberArray(_loc_5);
                    if (_loc_6.length == 2)
                    {
                        _loc_2.push(new Point(_loc_6[0], _loc_6[1]));
                    }
                    _loc_4++;
                }
            }
            return _loc_2;
        }// end function

        private function toNumberArray(param1:String) : Array
        {
            param1 = StringHelper.trim(param1);
            var _loc_2:* = param1.split(",");
            var _loc_3:Array = [];
            var _loc_4:int = 0;
            while (_loc_4 < _loc_2.length)
            {
                
                _loc_3.push(Number(_loc_2[_loc_4]));
                _loc_4++;
            }
            return _loc_3;
        }// end function

        public function init() : void
        {
            var _loc_1:* = ConfigManager.instance.getObjectByFileName("dramaEffect.xml");
            this.write(_loc_1);
            return;
        }// end function

        public function getDramaEffectInfo(param1:Object) : DramaEffectInfo
        {
            return this._map[param1];
        }// end function

        public static function get instance() : DramaEffectConfig
        {
            if (_instance == null)
            {
                _instance = new DramaEffectConfig;
            }
            return _instance;
        }// end function

    }
}
